#array functions
Explore tagged Tumblr posts
vinhjacker1 · 2 years ago
Text
How do you fill a PHP array dynamically (PHP, array, development)?
To dynamically fill a PHP array, you can use various methods to add elements to the array during runtime. Here are some common approaches:
Using array_push() function:
The array_push() function allows you to add one or more elements to the end of an array.
phpCopy code
$myArray = array(); // Initialize an empty array
// Dynamically add elements to the array array_push($myArray, "Element 1"); array_push($myArray, "Element 2"); array_push($myArray, "Element 3");
// Resulting array: ["Element 1", "Element 2", "Element 3"]
Using square brackets:
You can also use square brackets to add elements directly to the array.
phpCopy code
$myArray = array(); // Initialize an empty array
// Dynamically add elements to the array $myArray[] = "Element 1"; $myArray[] = "Element 2"; $myArray[] = "Element 3";
// Resulting array: ["Element 1", "Element 2", "Element 3"]
Associative array:
For associative arrays, you can set values dynamically by specifying the key.
phpCopy code
$myArray = array(); // Initialize an empty associative array
// Dynamically add elements to the array $myArray["name"] = "John"; $myArray["age"] = 30; $myArray["email"] = "[email protected]";
// Resulting array: ["name" => "John", "age" => 30, "email" => "[email protected]"]
Using loop:
You can use a loop to dynamically populate the array with elements.
phpCopy code
$myArray = array(); // Initialize an empty array
// Use a loop to add elements to the array for ($i = 1; $i <= 5; $i++) { $myArray[] = "Element " . $i; }
// Resulting array: ["Element 1", "Element 2", "Element 3", "Element 4", "Element 5"]
These methods allow you to dynamically add elements to a PHP array during development, making your code flexible and adaptable to various data requirements.
1 note · View note
orcelito · 3 months ago
Text
Got jumpscared by my own full legal name showing up in my email notifications bc I forgot I emailed my code to myself today just in case my VM ends up stopping working again (I got nervous & didn't wanna lose my progress lol)
Goldfish level memory retention
& the funny thing is that the email itself is just. This
Tumblr media
Full Legal Name code • hi
#speculation nation#title 'code' email is just 'hi'. with the .c file attached of course#honestly i had a very productive day in lab today. i got the core structure of the program down and made sure it all worked#testing it with One of the sorting algorithms. and it worked!!#the lab is to code functions for different kinds of sorts. like bubble sort selection sort and uhh. some other shit idr rn#and have the functions take timestamps from before and after they run the sorts to calculate the elapsed time#and we have to run this for array sizes of like. 10 50 500 etc etc up to like 50000 or smth? if i remember right.#and then once all that's done we take the output and graph the time elapsed for each type of sort/search per array sizes#so today at lab i made the random array generator function. a swap function. the execution function. bubble sort. and main.#main calls the execution function passing in the array sizes. execution(10); execution(50); etc#execution defines the array of that size. then calls the random number generator to populate the array. then passes it to the sort functions#tested with my one bubble sort function. which finished in like 0.00003 seconds or smth for array size 10#BUT taking the time stamps was tricky. there are a lot of ways to do that. and time(); in c is in full seconds#i ended up asking the TA if he had a recommendation for what to use bc theres a LOT of time functions out there#and full seconds isnt precise enough for this purpose. & he recommended clock()!!#records number of clock ticks which is NOT the same as seconds. but when u divide it by uh. forgetting it rn but it's a constant#that will turn it into actual seconds. clock tics per sec?? smth like that.#so anyways very productive 👍 i just need to set main up to call execution function for all the different array sizes#and then write all the functions for the different sorts/searches. but i have the core structure down with the bubble sort function#(specifically with the time stamps and the print function after) that i will copy-paste for all the other functions#and then inside them i put the basic code. none of it's complicated. all can be found on the internet easy.#SO!!!!! honestly i think itd take me less than an hour to finish. tho plotting out that graph is going to be annoying#something like 6 sizes per 5 sort/search functions. painstakingly copy pasting each one into excel or smth lol#but yea im content with how much ive gotten done. yippee!!!!#now i just need to finish my web programming lab before sunday night. blehhhhh
2 notes · View notes
nyctoheart · 5 months ago
Text
im trying to learn javascript...
Tumblr media
6 notes · View notes
fidius · 2 years ago
Text
This is not quite how coding works. Once you find out the proper way to do something in coding, there's an additional step where you feel like a huge idiot because in retrospect it is blindingly obvious that your way is too much work. Like
Wait, why don't you flicker when you're flying? What do you mean I can fly by just telekinetically pushing against the ground? No I've been consecutively teleporting myself successively higher off the ground a hundred times a minute. Yeah no it did take a huge amount of power but I just figured flying was hard. No I know bumblebees do it I just uh.
i love pitting classically trained magic users against self-taught magic users in sci-fi/fantasy but it shouldn’t be snobbish disdain for them it should be terror
183K notes · View notes
pierswife · 18 days ago
Text
You know, I could come up with a way to make my code a little cleaner, but what if 20+ IF/THEN statements instead--
1 note · View note
amplexadversary · 1 month ago
Text
I'm at a point where all my mechanical pencils are breaking to the point where I cannot keep them repaired, and so I've gone online to discover that nobody is making the kind I fucking use right now >_>
Also that apparently "pencil" means the same thing as "pen" if you're an internet search engine, and that "novelty" and "vintage/antique" are now apparently synonyms despite meaning wildly different things.
I just want to replace the exact thing I fucking have. I am going to start biting.
1 note · View note
aarunresearcher · 6 months ago
Text
United States flooring market size reached USD 74.6 Billion in 2024. Looking forward, IMARC Group expects the market to reach USD 134.9 Billion by 2033, exhibiting a growth rate (CAGR) of 6.8% during 2025-2033. Ongoing advancements in interior design, offering a vast array of choices that balance functionality, aesthetics, and sustainability, are primarily driving the market growth.
0 notes
orcelito · 3 months ago
Text
Started working on my C lab. Remembered how good of a position I left myself in after last week, so yay!! It won't take too much effort to finish.
I'm not gonna finish before lab tho, both bc I dont really have time (whoops I dragged my feet with starting it this morning) but also I realized. Well the sort functions are self-explanatory. Randomly generate an array and then sort it, timing how long each sort takes to do it. But then the search functions... *what* are we supposed to be searching???? That's. Not stated in the document. So I'm gonna ask the TA about that.
#speculation nation#also i think binary search needs them to be sorted already??? so uh. whats the deal here#but i got the bubble sort function done. gotta put in the code for insertion and selection sorts using the bones from the bubble sort#aka i copy pasted all the time stamp and print shit from the bubble sort to build off of. bc it's the same for these too#just that middle part. the loops themselves. those are different. but i can also find those online easy#also the professor literally Gave us the code in class. but im gonna double check them with online stuff too#just in case. since i wrote them down and he wrote them down on the board. several steps where mistakes could be made#the searches probably wont be difficult either. theyre still taking the same time stamps and printing thing from the sorts#just. searching instead. but *what* are they searching... thats what i need to know.#adding in the increased array sizes will be easy peasy. bc i just need to call the execution function additional times for each array size#then the code will do the rest.#graphing all of this output will take some time But so long as i can find out what im fuckin searching early in the class#i could still finish before the end of lab. plus i think i only really need my code checked off#like i gotta get my lab checked off before i can turn it in. which is why i have to have it done b4 the end of lab#even tho the lab is technically due at 11 pm tonight.#and i have to turn in my code And the graph i make from its output... but i dont Think the graph has to be checked off?? idk.#i'll ask i guess. either way i still feel like i'll finish with plenty of time. i got this 👍
1 note · View note
relto · 8 months ago
Text
gotta love that all the php docs you can find tell you that calling oci_new_descriptor will let you create an empty lob object, which keeps failing, and then i find a random bug report from 2006 about this exact thing not working and it turns out this function does in fact NOT create a valid lob object.
1 note · View note
joliebean · 4 months ago
Text
Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media
Slaystation Set by Joliebean
It's not my first rodeo with creating buy mode objects but it was def a challenge! I love makeup and I always dreamed of having a huge vanity table with lamps on a big mirror so why not make one for TS4?
Step into a world of style with The Slaystation Set by Jolie Home. This carefully curated collection includes everything your Sims need to create the perfect vanity corner: a cute vanity table for all their beauty rituals, a plush chair for comfort while getting ready, and an array of chic decor items that make the space truly shine.
💗 General Info 💗
Slaystation 2000 Vanity Table requires Vintage Glamour SP to function
the rest items are BGC
standalones
7 items
custom thumbnails
can be found in the catalogue by the word 'Joliebean'
my TOU
Download - Patreon (Free)
7K notes · View notes
jcmarchi · 10 months ago
Text
Master CUDA: For Machine Learning Engineers
New Post has been published on https://thedigitalinsider.com/master-cuda-for-machine-learning-engineers/
Master CUDA: For Machine Learning Engineers
CUDA for Machine Learning: Practical Applications
Structure of a CUDA C/C++ application, where the host (CPU) code manages the execution of parallel code on the device (GPU).
Now that we’ve covered the basics, let’s explore how CUDA can be applied to common machine learning tasks.
Matrix Multiplication
Matrix multiplication is a fundamental operation in many machine learning algorithms, particularly in neural networks. CUDA can significantly accelerate this operation. Here’s a simple implementation:
__global__ void matrixMulKernel(float *A, float *B, float *C, int N) int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; float sum = 0.0f; if (row < N && col < N) for (int i = 0; i < N; i++) sum += A[row * N + i] * B[i * N + col]; C[row * N + col] = sum; // Host function to set up and launch the kernel void matrixMul(float *A, float *B, float *C, int N) dim3 threadsPerBlock(16, 16); dim3 numBlocks((N + threadsPerBlock.x - 1) / threadsPerBlock.x, (N + threadsPerBlock.y - 1) / threadsPerBlock.y); matrixMulKernelnumBlocks, threadsPerBlock(A, B, C, N);
This implementation divides the output matrix into blocks, with each thread computing one element of the result. While this basic version is already faster than a CPU implementation for large matrices, there’s room for optimization using shared memory and other techniques.
Convolution Operations
Convolutional Neural Networks (CNNs) rely heavily on convolution operations. CUDA can dramatically speed up these computations. Here’s a simplified 2D convolution kernel:
__global__ void convolution2DKernel(float *input, float *kernel, float *output, int inputWidth, int inputHeight, int kernelWidth, int kernelHeight) int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; if (x < inputWidth && y < inputHeight) float sum = 0.0f; for (int ky = 0; ky < kernelHeight; ky++) for (int kx = 0; kx < kernelWidth; kx++) int inputX = x + kx - kernelWidth / 2; int inputY = y + ky - kernelHeight / 2; if (inputX >= 0 && inputX < inputWidth && inputY >= 0 && inputY < inputHeight) sum += input[inputY * inputWidth + inputX] * kernel[ky * kernelWidth + kx]; output[y * inputWidth + x] = sum;
This kernel performs a 2D convolution, with each thread computing one output pixel. In practice, more sophisticated implementations would use shared memory to reduce global memory accesses and optimize for various kernel sizes.
Stochastic Gradient Descent (SGD)
SGD is a cornerstone optimization algorithm in machine learning. CUDA can parallelize the computation of gradients across multiple data points. Here’s a simplified example for linear regression:
__global__ void sgdKernel(float *X, float *y, float *weights, float learningRate, int n, int d) int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) float prediction = 0.0f; for (int j = 0; j < d; j++) prediction += X[i * d + j] * weights[j]; float error = prediction - y[i]; for (int j = 0; j < d; j++) atomicAdd(&weights[j], -learningRate * error * X[i * d + j]); void sgd(float *X, float *y, float *weights, float learningRate, int n, int d, int iterations) int threadsPerBlock = 256; int numBlocks = (n + threadsPerBlock - 1) / threadsPerBlock; for (int iter = 0; iter < iterations; iter++) sgdKernel<<<numBlocks, threadsPerBlock>>>(X, y, weights, learningRate, n, d);
This implementation updates the weights in parallel for each data point. The atomicAdd function is used to handle concurrent updates to the weights safely.
Optimizing CUDA for Machine Learning
While the above examples demonstrate the basics of using CUDA for machine learning tasks, there are several optimization techniques that can further enhance performance:
Coalesced Memory Access
GPUs achieve peak performance when threads in a warp access contiguous memory locations. Ensure your data structures and access patterns promote coalesced memory access.
Shared Memory Usage
Shared memory is much faster than global memory. Use it to cache frequently accessed data within a thread block.
Understanding the memory hierarchy with CUDA
This diagram illustrates the architecture of a multi-processor system with shared memory. Each processor has its own cache, allowing for fast access to frequently used data. The processors communicate via a shared bus, which connects them to a larger shared memory space.
For example, in matrix multiplication:
__global__ void matrixMulSharedKernel(float *A, float *B, float *C, int N) __shared__ float sharedA[TILE_SIZE][TILE_SIZE]; __shared__ float sharedB[TILE_SIZE][TILE_SIZE]; int bx = blockIdx.x; int by = blockIdx.y; int tx = threadIdx.x; int ty = threadIdx.y; int row = by * TILE_SIZE + ty; int col = bx * TILE_SIZE + tx; float sum = 0.0f; for (int tile = 0; tile < (N + TILE_SIZE - 1) / TILE_SIZE; tile++) if (row < N && tile * TILE_SIZE + tx < N) sharedA[ty][tx] = A[row * N + tile * TILE_SIZE + tx]; else sharedA[ty][tx] = 0.0f; if (col < N && tile * TILE_SIZE + ty < N) sharedB[ty][tx] = B[(tile * TILE_SIZE + ty) * N + col]; else sharedB[ty][tx] = 0.0f; __syncthreads(); for (int k = 0; k < TILE_SIZE; k++) sum += sharedA[ty][k] * sharedB[k][tx]; __syncthreads(); if (row < N && col < N) C[row * N + col] = sum;
This optimized version uses shared memory to reduce global memory accesses, significantly improving performance for large matrices.
Asynchronous Operations
CUDA supports asynchronous operations, allowing you to overlap computation with data transfer. This is particularly useful in machine learning pipelines where you can prepare the next batch of data while the current batch is being processed.
cudaStream_t stream1, stream2; cudaStreamCreate(&stream1); cudaStreamCreate(&stream2); // Asynchronous memory transfers and kernel launches cudaMemcpyAsync(d_data1, h_data1, size, cudaMemcpyHostToDevice, stream1); myKernel<<<grid, block, 0, stream1>>>(d_data1, ...); cudaMemcpyAsync(d_data2, h_data2, size, cudaMemcpyHostToDevice, stream2); myKernel<<<grid, block, 0, stream2>>>(d_data2, ...); cudaStreamSynchronize(stream1); cudaStreamSynchronize(stream2);
Tensor Cores
For machine learning workloads, NVIDIA’s Tensor Cores (available in newer GPU architectures) can provide significant speedups for matrix multiply and convolution operations. Libraries like cuDNN and cuBLAS automatically leverage Tensor Cores when available.
Challenges and Considerations
While CUDA offers tremendous benefits for machine learning, it’s important to be aware of potential challenges:
Memory Management: GPU memory is limited compared to system memory. Efficient memory management is crucial, especially when working with large datasets or models.
Data Transfer Overhead: Transferring data between CPU and GPU can be a bottleneck. Minimize transfers and use asynchronous operations when possible.
Precision: GPUs traditionally excel at single-precision (FP32) computations. While support for double-precision (FP64) has improved, it’s often slower. Many machine learning tasks can work well with lower precision (e.g., FP16), which modern GPUs handle very efficiently.
Code Complexity: Writing efficient CUDA code can be more complex than CPU code. Leveraging libraries like cuDNN, cuBLAS, and frameworks like TensorFlow or PyTorch can help abstract away some of this complexity.
As machine learning models grow in size and complexity, a single GPU may no longer be sufficient to handle the workload. CUDA makes it possible to scale your application across multiple GPUs, either within a single node or across a cluster.
CUDA Programming Structure
To effectively utilize CUDA, it’s essential to understand its programming structure, which involves writing kernels (functions that run on the GPU) and managing memory between the host (CPU) and device (GPU).
Host vs. Device Memory
In CUDA, memory is managed separately for the host and device. The following are the primary functions used for memory management:
cudaMalloc: Allocates memory on the device.
cudaMemcpy: Copies data between host and device.
cudaFree: Frees memory on the device.
Example: Summing Two Arrays
Let’s look at an example that sums two arrays using CUDA:
__global__ void sumArraysOnGPU(float *A, float *B, float *C, int N) int idx = threadIdx.x + blockIdx.x * blockDim.x; if (idx < N) C[idx] = A[idx] + B[idx]; int main() int N = 1024; size_t bytes = N * sizeof(float); float *h_A, *h_B, *h_C; h_A = (float*)malloc(bytes); h_B = (float*)malloc(bytes); h_C = (float*)malloc(bytes); float *d_A, *d_B, *d_C; cudaMalloc(&d_A, bytes); cudaMalloc(&d_B, bytes); cudaMalloc(&d_C, bytes); cudaMemcpy(d_A, h_A, bytes, cudaMemcpyHostToDevice); cudaMemcpy(d_B, h_B, bytes, cudaMemcpyHostToDevice); int blockSize = 256; int gridSize = (N + blockSize - 1) / blockSize; sumArraysOnGPU<<<gridSize, blockSize>>>(d_A, d_B, d_C, N); cudaMemcpy(h_C, d_C, bytes, cudaMemcpyDeviceToHost); cudaFree(d_A); cudaFree(d_B); cudaFree(d_C); free(h_A); free(h_B); free(h_C); return 0;
In this example, memory is allocated on both the host and device, data is transferred to the device, and the kernel is launched to perform the computation.
Conclusion
CUDA is a powerful tool for machine learning engineers looking to accelerate their models and handle larger datasets. By understanding the CUDA memory model, optimizing memory access, and leveraging multiple GPUs, you can significantly enhance the performance of your machine learning applications.
0 notes
clonewarsahsoka · 1 year ago
Text
I'm slowly becoming interested in computer science >.<
0 notes
dreadwedge · 2 years ago
Text
Bet you didn’t think a cute little baby goat like me, resting beneath a black walnut tree to escape the summer sun, would be proficient in Microsoft Excel, did you. Bet you didn’t expect me to know how to optimize a spreadsheet by implementing conditional formatting rules huh. Bet you took one look at me and thought “no way this kid knows how to use the VLOOKUP function.” Well guess what, I do. I know a diverse array of useful formulas and my body is capable of digesting poison ivy. I eat that shit like potato chips. Get the fuck out of my paddock
30K notes · View notes
Text
Om Digi Group's Website Developers: Masters of Digital Craftsmanship
Crafting Digital Excellence
Om Digi Group's website developers are renowned for their mastery in crafting digital excellence. With expertise in a wide array of programming languages and development frameworks, they bring creativity and precision to every project they undertake. From conceptualization to execution, their attention to detail ensures that each website they develop is not just functional but also visually stunning.
Tailored Solutions for Unique Needs
Understanding that every client has unique goals and requirements, Om Digi Group's website developers offer tailored solutions to meet specific needs. They collaborate closely with clients, delving into their objectives, target audience, and brand identity. This collaborative approach ensures that each website is custom-built to resonate with the client's vision and objectives.
Innovation Driven Development
Innovation is ingrained in Om Digi Group's ethos, and its website developers are at the forefront of driving digital innovation. They stay updated on the latest technologies and trends, constantly exploring new tools and techniques to enhance their craft. By embracing innovation, they create websites that not only meet but exceed expectations, setting new standards in the industry.
User-Centric Design Philosophy
Om Digi Group's website developers prioritize user experience above all else. They understand that a website's success hinges on its ability to engage and delight users. Therefore, they adopt a user-centric design philosophy, focusing on intuitive navigation, clear calls-to-action, and seamless interactions. By putting the user first, they ensure that each website delivers a memorable and engaging experience for visitors.
#Crafting Digital Excellence#Om Digi Group's website developers are renowned for their mastery in crafting digital excellence. With expertise in a wide array of program#they bring creativity and precision to every project they undertake. From conceptualization to execution#their attention to detail ensures that each website they develop is not just functional but also visually stunning.#Tailored Solutions for Unique Needs#Understanding that every client has unique goals and requirements#Om Digi Group's website developers offer tailored solutions to meet specific needs. They collaborate closely with clients#delving into their objectives#target audience#and brand identity. This collaborative approach ensures that each website is custom-built to resonate with the client's vision and objectiv#Innovation Driven Development#Innovation is ingrained in Om Digi Group's ethos#and its website developers are at the forefront of driving digital innovation. They stay updated on the latest technologies and trends#constantly exploring new tools and techniques to enhance their craft. By embracing innovation#they create websites that not only meet but exceed expectations#setting new standards in the industry.#User-Centric Design Philosophy#Om Digi Group's website developers prioritize user experience above all else. They understand that a website's success hinges on its abilit#they adopt a user-centric design philosophy#focusing on intuitive navigation#clear calls-to-action#and seamless interactions. By putting the user first#they ensure that each website delivers a memorable and engaging experience for visitors.#website developers
1 note · View note
rattkinng · 1 year ago
Text
I hate pointers so much
0 notes
assaultmystic · 3 months ago
Text
one function of transmisogynistic hypervisibility is that when you are opinionated, people will take it as read that you are outlining more or less a policy position by every word you say. that you might want to speak for yourself is not considered. you, tranny, are answerable for the whole world! what a shackle! and worst of all is how it gets in your head. every conceivable thing ever sits arrayed for you to organise and submit for judgement every time you open your mouth.
2K notes · View notes